import { defineStore } from 'pinia'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { login } from '@/api/index.js'

import { ElMessage } from 'element-plus'
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)

export const employeeStore = defineStore('employee', {
  state: () => {
    return { empInfo: {} }
  },

  actions: {
    async setToken(data) {
      const res = await login(data)
      this.empInfo = res.data
      ElMessage.success('登录成功')
    },
    logout() {
      this.empInfo = {}
    }
  },
  persist: true
})

export default pinia
